const url = require('url');

var strUrl = 'http://www.demo.com?a=123&b=456#admin' ;

//var obj = url.parse(strUrl);

var obj = {
    protocol:'https:',
    hostname:'www.demo.com',
    port:'80',
    hash:'#admin',
    search:'?a=123&b=456',
    pathname:'/'
}

console.log(obj);

console.log(url.format(obj));